//
//  ByCommonCache.m
//  beibei_ios
//
//  Created by pro on 16/5/10.
//  Copyright © 2016年 hebidu. All rights reserved.
//

#import "ByCommonCache.h"


#define KEY_USER_INFO @"KEY_USER_INFO"              // 用户信息
#define KEY_HOME_DATA @"KEY_HOME_DATA"              // 首页数据

#define KEY_SEARCH_HISTORY @"KEY_SEARCH_HISTORY"    // 历史搜索
#define KEY_CONTRACT_IFNO_FOR_LESSER @"KEY_CONTRACT_IFNO_FOR_LESSER"      // 合同信息-房东
#define KEY_CONTRACT_IFNO_FOR_RENTER @"KEY_CONTRACT_IFNO_FOR_RENTER"      // 合同信息-房东

#define KEY_PUSH_INFO @"KEY_PUSH_INFO"              // 推送私信

#define KEY_LOCK_MAC @"KEY_LOCK_MAC"                // 钥匙 锁

@implementation ByCommonCache

#pragma mark - 用户
/** 存储用户信息 */
+ (void)setUserInfo:(ByNetUserModel *)userModel {
    
    [ByCoreCacheSqlite3 setObjectWithKey:KEY_USER_INFO value:userModel expireTime:3600 * 24 * 30];
}
/** 获取用户信息 */
+ (ByNetUserModel *)getUserInfo {

    ByNetUserModel *user = [ByCoreCacheSqlite3 getValueWithKey:KEY_USER_INFO];
    if (user != nil) {
        // 更新数据库中的用户信息 修改update_time
        [self setUserInfo:user];
    }
    
    return user;
}

//#pragma mark - 首页
///** 存储首页数据 */
//+ (void)setHomeData:(ByNetHomeModel *)model {
//    
//    [ByCoreCacheSqlite3 setObjectWithKey:KEY_HOME_DATA value:model expireTime:3600 * 24 * 30];
//
//}
///** 获取首页数据 */
//+ (ByNetHomeModel *)getHomeData {
//    
//    ByNetHomeModel *model = [ByCoreCacheSqlite3 getValueWithKey:KEY_HOME_DATA];
//    return model;
//}

#pragma mark - 搜索历史
/** 存储用户信息 */
+ (void)setSearchHistory:(NSMutableArray *)history {
    [ByCoreCacheSqlite3 setObjectWithKey:KEY_SEARCH_HISTORY value:history expireTime:3600 * 24 * 30];
}
///** 获取用户信息 */
+ (NSMutableArray *)getSearchHistory {
    NSMutableArray *history = [ByCoreCacheSqlite3 getValueWithKey:KEY_SEARCH_HISTORY];
    return history;
}



#pragma mark - 合同信息
/** 存储合同信息 */
+ (void)setContractInfoForLesser:(NSArray *)info uid:(NSString *)uid {
    NSString *key = [NSString stringWithFormat:@"%@_%@", KEY_CONTRACT_IFNO_FOR_LESSER, uid];
    [ByCoreCacheSqlite3 setObjectWithKey:key value:info expireTime:3600 * 12];
}
///** 获取合同信息 */
+ (NSArray *)getContractInfoForLesser:(NSString *)uid {
    NSString *key = [NSString stringWithFormat:@"%@_%@", KEY_CONTRACT_IFNO_FOR_LESSER, uid];
    NSArray *info = [ByCoreCacheSqlite3 getValueWithKey:key];
    return info;
}
/** 存储合同信息 */
+ (void)setContractInfoForRenter:(NSArray *)info uid:(NSString *)uid {
    NSString *key = [NSString stringWithFormat:@"%@_%@", KEY_CONTRACT_IFNO_FOR_RENTER, uid];
    [ByCoreCacheSqlite3 setObjectWithKey:key value:info expireTime:3600 * 12];
}
///** 获取合同信息 */
+ (NSArray *)getContractInfoForRenter:(NSString *)uid {
    NSString *key = [NSString stringWithFormat:@"%@_%@", KEY_CONTRACT_IFNO_FOR_RENTER, uid];
    NSArray *info = [ByCoreCacheSqlite3 getValueWithKey:key];
    return info;
}

#pragma mark - bool 是否推送私信
/** 存储bool状态 */
+ (void)setPushPrivateLetter:(NSString *)ispush {
    NSString *key = [NSString stringWithFormat:@"%@", KEY_PUSH_INFO];
    [ByCoreCacheSqlite3 setObjectWithKey:key value:ispush expireTime:3600 * 24 * 30];
}
///** 获取bool状态 */
+ (BOOL)getPushInfo {
    NSString *key = [NSString stringWithFormat:@"%@", KEY_PUSH_INFO];
    NSString *info = [ByCoreCacheSqlite3 getValueWithKey:key];
    return [info boolValue];
}


@end
